Skip to content

grep: support POSIX collating symbols [[.c.]] in bracket expressions - #264

Open
yunusarda-sudo wants to merge 3 commits into
uutils:mainfrom
yunusarda-sudo:grep-collating-symbols
Open

yunusarda-sudo wants to merge 3 commits into
uutils:mainfrom
yunusarda-sudo:grep-collating-symbols

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

In POSIX and GNU grep, a single-character collating symbol [.c.] inside a bracket expression stands for that character in the C locale (e.g. [[.a.]] matches a, and [^[:alnum:][.-.]_] is the standard way to put - into the character class).

Multi-character names (like [[.space.]] or [[.tab.]]) and empty symbols ([[..]]) are rejected by GNU grep with Invalid collation character (exit code 2). An unclosed [. within a bracket expression is rejected with Unmatched [, [^, [:, [., or [=.

Previously, uutils/grep passed bracket patterns directly to Oniguruma, which does not recognize [. ... .] syntax. As a result, [[.a.]] was interpreted as {[, ., a} followed by literal ], matching the wrong characters and accepting invalid symbol names without errors.

This change:

  • Validates collating symbols in bracket expressions for Basic (-G) and Extended (-E) modes.
  • Rejects unclosed [. with Unmatched [, [^, [:, [., or [= and multi-character/empty symbols with Invalid collation character.
  • Translates single-character symbols into safe bracket characters according to regex character set rules (placing non-range hyphens safely at the end of the class, handling caret, and closing bracket).
  • Leaves -F fixed strings and non-collating patterns unaffected with zero overhead.

Fixes #158

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.54%. Comparing base (6009851) to head (ae326ac).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #264      +/-   ##
==========================================
+ Coverage   97.28%   97.54%   +0.25%     
==========================================
  Files           6        6              
  Lines        2287     2482     +195     
  Branches      247      276      +29     
==========================================
+ Hits         2225     2421     +196     
+ Misses         62       61       -1     
Flag Coverage Δ
macOS_latest 98.37% <100.00%> (+0.18%) ⬆️
ubuntu_latest 98.37% <100.00%> (+0.18%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing yunusarda-sudo:grep-collating-symbols (ae326ac) with main (9aa25a6)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grep - POSIX collating symbols [[.c.]] are not recognised in bracket expressions

1 participant